Template Literals 與 Destructuring


Posted by cmtilo on 2021-04-30

再也不需要字串拼接:Template Literals

、、 可以放多行字串

例1

var str =、
hey
hi
、

例2

console.log(、hello, ${name.toUpperCase} now is ${new Date( )}、)

聽起來很酷的 Destructuring:解構

例1

const arr = [1, 2, 3, 4]
var [first, second, third, fourth] = arr

例2

const obj = {
 name : 'nick'
 age : 30
 address : 'taiwan'
}
var {name, age, address} = obj

例3

function test({a, b}) {
 console.log(a)
}
test({
 a : 1,
 b : 2
})

#template literals #destructuring







Related Posts

Mongoose - To-Do-List v2

Mongoose - To-Do-List v2

如何用 sequel pro 連到之前 xampp 的資料庫

如何用 sequel pro 連到之前 xampp 的資料庫

輸入資料 是否為自然數的 判斷演算法

輸入資料 是否為自然數的 判斷演算法


Comments